package com.fshuqing.learing.spring.applicationcontext;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author fshuqing
 */
public class App {
    public static void main(String[] args) {
        String basePackages = "com.fshuqing.learing.spring.applicationcontext";
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(basePackages);

        // 第一种，直接@Autowired，@Resource都可以，可以改为构造方法注入
        FirstApplicationContext firstApplicationContext = context.getBean(FirstApplicationContext.class);
        firstApplicationContext.show();

        // 第二种， implements ApplicationContextAware
        SecondApplicationContext secondApplicationContext = context.getBean(SecondApplicationContext.class);
        secondApplicationContext.show();

        // 第三种 spring 4.3新特性，如果有两个以上的有参数构造函数，则找无参构造函数。
        ThreeApplicationContext threeApplicationContext = context.getBean(ThreeApplicationContext.class);
        threeApplicationContext.show();

        EchoBeanPostProcessor echoBeanPostProcessor = context.getBean(EchoBeanPostProcessor.class);
        int i = echoBeanPostProcessor.hashCode();
        System.out.println("i = " + i);

        context.close();
    }
}
